package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.Recommend;
import cn.wolfcode.luowowo.article.mapper.RecommendMapper;
import cn.wolfcode.luowowo.article.service.IRecommendService;
import cn.wolfcode.luowowo.common.query.RecommendQueryObject;
import cn.wolfcode.luowowo.common.query.StrategyThemeCopyQueryObject;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class RecommendServiceImpl implements IRecommendService {
    @Autowired
    private RecommendMapper recommendMapper;

    public PageInfo query(RecommendQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Recommend> list = recommendMapper.selectForList(qo);
        return new PageInfo(list);
    }

    public void deleteById(Long id) {
        recommendMapper.deleteByPrimaryKey(id);
    }

    public void saveOrUpdate(Recommend recommend) {
        if(recommend.getId() == null){
            //新增操作
            recommendMapper.insert(recommend);
        }else{
            //更新操作
            recommendMapper.updateByPrimaryKey(recommend);
        }
    }

    public List<Recommend> selectAllRecommendsByMonth(RecommendQueryObject qo) {

        return recommendMapper.selectAllRecommendsByMonth(qo);
    }

    public List<Recommend> selectAllByThemeId(StrategyThemeCopyQueryObject qo) {
        return recommendMapper.selectAllByThemeId(qo);
    }
}
